/* eslint-disable eslint-comments/disable-enable-pair */

/* eslint-disable import/no-mutable-exports */
let CURRENT = 'NULL';

/**
 * @description 接受权限组件并处理新的权限列表到CURRENT常量，处理完成返回权限组件
 * @param {*} Authorized
 */
const renderAuthorize = Authorized => currentAuthority => {
  if (currentAuthority) {
    if (typeof currentAuthority === 'function') {
      // currentAuthority是函数的话 函数要return [object String]||NULL
      CURRENT = currentAuthority();
    }
    if (Object.prototype.toString.call(currentAuthority) === '[object String]' || Array.isArray(currentAuthority)) {
      CURRENT = currentAuthority;
    }
  } else {
    CURRENT = 'NULL';
  }
  //   修改CURRENT常量后并导出权限组件
  return Authorized;
};

export { CURRENT };
export default Authorized => renderAuthorize(Authorized);
